class index_bgUI extends egret.Sprite {

    public constructor() {
        super();
        this.once(egret.Event.ADDED_TO_STAGE, this.createView, this);
    }
    private createView() {
        //添加背景
        var bg = drawReactShape(null, 0, 0, 640, 1136, 0x16c5ee);
        this.addChild(bg);

        var bg_shuiwen = createBitmap("bg_shuiwen_png", -560, 0);
        this.addChild(bg_shuiwen);
        var bg_shuiwen2 = createBitmap("bg_shuiwen_png", -560, -1136);
        this.addChild(bg_shuiwen2);
        egret.Tween.get(bg_shuiwen, { loop: true }).to({ x: 0, y: 1136 }, 10000);
        egret.Tween.get(bg_shuiwen2, { loop: true }).to({ x: 0, y: 0 }, 10000);

        //添加音乐logo
        var music_logo = createBitmap("music_logo_png", 580, 50);
        this.$stage.addChildAt(music_logo, 100);
        // this.setChildIndex(music_logo,100);
        music_logo.anchorOffsetX = music_logo.width * .5;
        music_logo.anchorOffsetY = music_logo.height * .5;
        music_logo.touchEnabled = true;
        egret.Tween.get(music_logo, { loop: true }).to({ rotation: 360 }, 3000);
        this.touchEnabled = true;
        music_logo.addEventListener(egret.TouchEvent.TOUCH_BEGIN, function () {
            music_logo.touchEnabled = true;
            this.addEventListener(egret.TouchEvent.TOUCH_MOVE, music_move, this);
        }, this);
        music_logo.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, function () {
            music_logo.touchEnabled = true;
           
            //music_logo.addEventListener(egret.TouchEvent.TOUCH_TAP,zanting, this)
            //this.removeEventListener(egret.TouchEvent.TOUCH_MOVE, music_move, this);
        }, this);
        function music_move(e) {
            music_logo.x = e.$stageX;
            music_logo.y = e.$stageY;
            music_logo.touchEnabled = false;
        };

        //添加音乐
        var sound = new egret.Sound;
        var soundChannel;
        var totalLength = 0;
        var curTime = 0;
        sound.addEventListener(egret.Event.COMPLETE, function () {
            soundChannel = sound.play(curTime, 1);
            totalLength = sound.length;
        }, this);
        sound.load("resource/assets/let_it_go.mp3");
        //通过点击音乐logo播放/暂停音乐
        music_logo.addEventListener(egret.TouchEvent.TOUCH_TAP, zanting, this)
        function zanting() {
            if (soundChannel == null) {
                soundChannel = sound.play(curTime);
                egret.Tween.resumeTweens(music_logo);
            } else {
                curTime = soundChannel.position;
                soundChannel.stop();
                soundChannel = null;
                egret.Tween.pauseTweens(music_logo);
            }
        }
    }
}